-
Notifications
You must be signed in to change notification settings - Fork 6
Avoid generation of original SMILES in augmentation #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
aditya0by0
commented
Dec 6, 2025
- See Wiki https://github.com/ChEB-AI/python-chebai/wiki/SMILES-Augmentation#snippet-of-augmented-smiles
sfluegel05
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I am wondering why we need the original SMILES at all. Why don't we only do the random SMILES generation (which then might include the original SMILES, but not necessarily)?
|
The motivation for including the original SMILES strings in the augmented dataset comes from two considerations:
Below is an example illustrating such a case:
and check its generated SMILES here: https://github.com/ChEB-AI/python-chebai/wiki/SMILES-Augmentation#snippet-of-augmented-smiles below program reinforces this theory import random
from itertools import cycle, permutations, product
from rdkit import Chem
AUG_SMILES_VARIATIONS = 1000000000
def generate_augmented_smiles(smiles: str) -> list[str]:
mol: Chem.Mol = Chem.MolFromSmiles(smiles)
if mol is None:
return [smiles] # if mol is None, return original SMILES
# sanitization set to False, as it can alter the fragment representation in ways you might not want.
# As we don’t want RDKit to "fix" fragments, only need the fragments as-is, to generate SMILES strings.
frags = Chem.GetMolFrags(mol, asMols=True, sanitizeFrags=False)
augmented = set()
frag_smiles: list[set] = []
for frag in frags:
atom_ids = [atom.GetIdx() for atom in frag.GetAtoms()]
random.shuffle(atom_ids) # seed set by lightning
atom_id_iter = cycle(atom_ids)
frag_smiles.append(
{
Chem.MolToSmiles(frag, rootedAtAtom=next(atom_id_iter), doRandom=True)
for _ in range(AUG_SMILES_VARIATIONS)
}
)
if len(frags) > 1:
for perm in permutations(frag_smiles):
for combo in product(*perm):
augmented.add(".".join(combo))
if smiles in augmented:
print("Found original SMILES in augmented set.")
break
else:
augmented = frag_smiles[0]
if smiles in augmented:
print("Found original SMILES in augmented set.")
else:
print("Original SMILES NOT found in augmented set.")
if __name__ == "__main__":
test_smiles = "[F-].[H][N]([H])([H])[Ag+][N]([H])([H])[H]"
generate_augmented_smiles(test_smiles) |
|
I would argue that the computer vision approach cannot be directly applied to SMILES. In computer vision, there is usually a "real" image and "distorted / modified" versions of the image. In SMILES, I don't see a clear distinction why the ChEBI-provided SMILES should be the "real" one that needs to be kept - all other SMILES strings are just as valid. The question then becomes: Which kind of SMILES do our users use? Is it the ChEBI-style SMILES? Is it the RDKit-canonical SMILES? I don't know. Fun fact: The reason why we can't reproduce the ChEBI-style SMILES is that they have their own library for that: https://github.com/chembl/libRDChEBI (currently, I don't see a use case where we would need to reproduce ChEBI's exact SMILES, but if it arises, we should use this library). Anyway, since I don't have a better suggestion, let's keep the original ChEBI-SMILES for now. |